﻿using Org.BouncyCastle.Utilities.Encoders;
using System.Text;

namespace 加密算法
{
    internal class Program1
    {
        static void Main1(string[] args)
        {
            //MD5
            Console.WriteLine(SM3Helper.Encrypt("爱游戏爱编程"));
        }
        static void Main2(string[] args)
        {
            //MD5
            Console.WriteLine(MD5Helper.GetMD5("爱游戏爱编程"));

            //SM3
            //Console.WriteLine(SM3Helper.Encrypt("爱游戏爱编程"));

            //SHA512
            //Console.WriteLine(SHAHelper.Encryption("爱游戏爱编程"));

            ////SM4
            //// 示例明文
            //byte[] plaintextBytes = Encoding.UTF8.GetBytes("爱游戏爱编程");
            //// 加密
            //byte[] encryptedBytes = SM4Helper.EncryptSM4(plaintextBytes);
            //string encryptedStr = Hex.ToHexString(encryptedBytes);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密
            //byte[] decryptedBytes = SM4Helper.DecryptSM4(encryptedBytes);
            //string decryptedStr = Encoding.UTF8.GetString(decryptedBytes);
            //Console.WriteLine("Decrypted: " + decryptedStr);

            ////AES
            //// 示例明文
            //byte[] plaintextBytes = Encoding.UTF8.GetBytes("爱游戏爱编程");
            //// 加密
            //byte[] encryptedBytes = AESHelper.EncryptAES(plaintextBytes);
            //string encryptedStr = Hex.ToHexString(encryptedBytes);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密
            //byte[] decryptedBytes = AESHelper.DecryptAES(encryptedBytes);
            //string decryptedStr = Encoding.UTF8.GetString(decryptedBytes);
            //Console.WriteLine("Decrypted: " + decryptedStr);

            ////DES
            //// 示例明文
            //byte[] plaintextBytes = Encoding.UTF8.GetBytes("爱游戏爱编程");
            //// 加密
            //byte[] encryptedBytes = DESHelper.EncryptDES(plaintextBytes);
            //string encryptedStr = Hex.ToHexString(encryptedBytes);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密
            //byte[] decryptedBytes = DESHelper.DecryptDES(encryptedBytes);
            //string decryptedStr = Encoding.UTF8.GetString(decryptedBytes);
            //Console.WriteLine("Decrypted: " + decryptedStr);

            //SM2
            //string publicKey = string.Empty;
            //string privateKey = string.Empty;
            //SM2Helper.GenerateSM2KeyPair(out privateKey, out publicKey);
            //string message = "爱游戏爱编程";
            //// 加密
            //string encryptedStr = SM2Helper.EncryptSM2(message, publicKey);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密
            //string decryptedStr = SM2Helper.DecryptSM2(encryptedStr, privateKey);
            //Console.WriteLine("Decrypted: " + decryptedStr);


            //RSA
            // 生成密钥对
            //RSAHelper.GenerateRSAKeyPair(out var publicKey, out var privateKey);
            //// 将密钥序列化为字节数组，便于传递或保存
            //byte[] publicKeyBytes = RSAHelper.PublicKeyToBytes(publicKey);
            //byte[] privateKeyBytes = RSAHelper.PrivateKeyToBytes(privateKey);
            //byte[] message = Encoding.UTF8.GetBytes("爱游戏爱编程");
            //// 加密
            //byte[] encryptedBytes = RSAHelper.EncryptRSA(message, publicKeyBytes);
            //string encryptedStr = Hex.ToHexString(encryptedBytes);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密
            //byte[] decryptedBytes = RSAHelper.DecryptRSA(encryptedBytes, privateKeyBytes);
            //string decryptedStr = Encoding.UTF8.GetString(decryptedBytes);
            //Console.WriteLine("Decrypted: " + decryptedStr);


            //DSA
            // 生成密钥对
            //var keys = DSAHelper.GenerateDSAKeyPair();
            //byte[] message = Encoding.UTF8.GetBytes("爱游戏爱编程");
            //// 加密
            //byte[] encryptedBytes = DSAHelper.SignDSA(message, keys.Private);
            //string encryptedStr = Hex.ToHexString(encryptedBytes);
            //Console.WriteLine("Encrypted: " + encryptedStr);

            //// 解密签名是否正确
            //bool result =  DSAHelper.VerifyDSA(message, encryptedBytes, keys.Public);
            //Console.WriteLine("Decrypted: " + result);

        }
    }
}
